<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
		<link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
		<title>区块链推广管理中心</title>
	</head>
	<style>
		body{
			background: #ffffff;
		}
		.main{
			width: 80%;
			margin: 0 auto;
		}
		.main>.title{
			text-align: center;
			margin-top: 5%;
		}
		#template{
			display: none;
		}
	</style>

	<body>
		<div class='main' style="position: relative;">
			<a href="/telegram.html" style="position: absolute; top: -10px;"><img src="http://cmanage.shinechain.io/imgs/return.jpg" height="48" width="48" style="vertical-align:middle;" /></a>
		<p><h2 class='title'>定时发送信息</h2></p>
	
	<div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_bd weui_cell_primary">
                <textarea class="weui_textarea"  id="mytextarea" placeholder="消息内容" rows="3"></textarea>
                <div class="weui_textarea_counter"><span class="count" id="count">0</span>/<span class="count_max" id="count_max">500</span></div>
                
            </div>
            
        </div>
        
    </div>
    
    <h5>规则：</h5>
                在<input type="text" id='sendMsgStartMin' size="1"/>分钟后开始发送第一次信息，
             	之后每隔<input type="text" id='sendMsgOnTime' size="1"/>分钟自动发送一次信息，
                发送<input type="text" id='sendMsgTimes' size="1"/>次信息后停止发送(输入-1则为无数次)
                
                <br />
	<div class="weui_btn_area">
        <a id="formSubmitBtn" href="javascript:" class="weui_btn weui_btn_primary">提交</a>
    </div>
    <div class="weui-cells">
  <div class="weui-cell">
    
  </div>
</div>
</div>

		<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
$(function(){
	var ip = 'http://bot.shinechain.io';
 	var getInfo = function () {
			$.get(ip + '/botApi/getAll', function(res) {
				$('#mytextarea').text(res.sendMsgOnTimeStr);
                $('#sendMsgStartMin').val(res.sendMsgStartMin);
                $('#sendMsgOnTime').val(res.sendMsgOnTime);
                $('#sendMsgTimes').val(res.sendMsgTimes);
			});
		}
			getInfo();		
	$('textarea').on('input', function(){
		var max =  $(this).parent().find('.count_max').text();
		var text = $(this).val();
		var len = text.length;
		$(this).parent().find('.count').text(len);    
		if(len > max){
			$(this).closest('.weui_cell').addClass('weui_cell_warn');
		} else {
			$(this).closest('.weui_cell').removeClass('weui_cell_warn');
		}
	});
  
  
  $('#formSubmitBtn').click(function(){
  	
	var sendMsgOnTimeStr = $('#mytextarea').val();
	var sendMsgStartMin = $('#sendMsgStartMin').val();
	var sendMsgOnTime = $('#sendMsgOnTime').val();
	var sendMsgTimes = $('#sendMsgTimes').val();
	var jsonArr = {sendMsgOnTimeStr,sendMsgStartMin,sendMsgOnTime,sendMsgTimes};
	
		$.ajax({
                url: ip + '/botApi/sendMsgOnTime',
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                data: JSON.stringify(jsonArr),
                success: function(res) {
                	$('#mytextarea').text(res.sendMsgOnTimeStr);
                	$('#sendMsgStartMin').text(res.sendMsgStartMin);
                	$('#sendMsgOnTime').text(res.sendMsgOnTime);
                	$('#sendMsgTimes').text(res.sendMsgTimes);
					alert('提交成功');
                },
       })
  });
})
</script>
</body>
</html>